<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ page isELIgnored="false"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<!DOCTYPE html>
<%
	String path = request.getContextPath();
%>
<html>
<head>

<link rel="stylesheet" type="text/css"
	href="<%=path%>/script/easyUI-1.4/themes/bootstrap/easyui.css">
<link rel="stylesheet" type="text/css"
	href="<%=path%>/script/easyUI-1.4/themes/icon.css">
<script type="text/javascript"
	src="<%=path%>/script/easyUI-1.4/jquery-3.2.1.min.js"></script>
<script type="text/javascript"
	src="<%=path%>/script/easyUI-1.4/jquery.easyui.min.js"></script>
<script type="text/javascript"
	src="<%=path%>/script/easyUI-1.4/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript" charset="utf-8"
	src="<%=path%>/script/utf8-jsp/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8"
	src="<%=path%>/script/utf8-jsp/ueditor.all.min.js">
	
</script>
<script type="text/javascript" charset="utf-8"
	src="<%=path%>/script/utf8-jsp/lang/zh-cn/zh-cn.js"></script>
<script type="text/javascript">
		

	$(function() {
		$('#key').combobox({
			onSelect: function(record){
				var value=record.keyValue;
				$('#commitkey').textbox('setValue',value);
			}
		});
	
		$('#fileTree').tree({    
		    url:'<%=path%>/guancangAction/getFileTreeData'   ,
		    onSelect: function(node){
		    	if(node.text=="点击新增文件夹"){
		    		//说明用户选择的是编辑文件夹
		    		$('#fileTree').tree("beginEdit",node.target);
		    		if(node.text==""){
		    			$('#fileTree').tree('update', {
		    				target: node.target,
		    				text: '点击新增文件夹'
		    			});
		    		}
		    	}
		    	$('#wenjianjia').val(node.text);
			},
			onAfterEdit:function(node){
				$('#wenjianjia').val(node.text);
			}
		});  
		
		

		  $("#saveBtn").bind('click',function(){
			  
			  var isValid = $("#form").form('validate');
			  
			  if(!isValid){
				  //表单验证失败
			  }else{
				  //说明表单验证成功，ajax提交表单
				 
				    $.ajax({
			            //几个参数需要注意一下
			                type: "POST",//方法类型
			                dataType: "json",//预期服务器返回的数据类型
			                url: "<%=path%>/guancangAction/saveShoucang",
			                data: $('#form').serialize(),
			                success: function (result) {
			                    	
			                    if(result.msg != null && result.msg != ""){
			                    	//保存成功
			                    	$.messager.confirm('提示',result.msg,function(r){    
			                    	  location.href="<%=path%>/views/user/main.jsp"; 
			                    	});
			                    }
			                    
			                },
			                error : function() {
			                    alert("系统异常！");
			                }
			            });
				  
				  
			  }
			  
			  
  });
		
		  $("#pinglunBtn").bind("click",function(){
			  var content= $("#pinglunContent").val();
			  var articleId=${article.id};
			  var dataParam={"content":content,"articleId":articleId};
			  
			    $.ajax({
		            //几个参数需要注意一下
		                type: "POST",//方法类型
		                dataType: "json",//预期服务器返回的数据类型
		                url: "<%=path%>/articleAction/pinglun",
		                data: dataParam,
		                success: function (result) {
		                    	
		                	 if(result.errMsg != null && result.errMsg != ""){
		                			 $.messager.alert('提示',result.errMsg);  
			                    }else{
		                    	//评论成功
			                    	$.messager.confirm('提示',result.msg,function(r){    
			                    	  location.href="<%=path%>/guancangAction/articleDescView?articleId=${article.id}"; 
			                    	});
		                         }
		                    
		                },
		                error : function() {
		                    alert("系统异常！");
		                }
		            });
			  
		  })
		  
	})
	
	
	function shoucang(articleId){
		$("#visible").css("visibility","visible");
		var dataParm={"articleId":articleId};
	    $.ajax({
            //几个参数需要注意一下
                type: "POST",//方法类型
                dataType: "json",//预期服务器返回的数据类型
                url: "<%=path%>/guancangAction/isshoucangquanxian",
                data: dataParm,
                success: function (result) {
                    	
                    if(result.msg != null && result.msg != ""){
                    	$('#win').window({    
                		    width:380,    
                		    height:500,    
                		    modal:true ,
                		    title:"转藏到我的图书馆"
                		}); 
                    }else{
                    	$.messager.confirm('提示',result.errMsg,function(r){    
              			  location.href="<%=path%>/views/user/main.jsp";
              			});  
                    }
                    
                },
                error : function() {
                    alert("系统异常！");
                }
            });
		
	};
	
	
	//查看文章作者信息
	function userDesc(articleId){
	       top.location.href="<%=path%>/userAction/userDesc?articleId="+articleId;
		
	}
	
	function showindex(){
		location.href="<%=path%>/userAction/login";
	}
</script>

</head>
<body class="easyui-layout" >
<div data-options="region:'north'" style="height:100px;">
		<div style="margin-left: 100px;margin-top: 20px">
    		<img alt="hello" src="<%=path%>/img/per_lib_logo.jpg" width="50px" height="50px" align="top">
    		<font size="6px" onclick="showindex();">个人图书馆</font>
    		<hr style="width:2px;height:30px;margin-top: -40px;margin-left:240px"></hr>
    	</div>
    	<div style="margin-top: -48px;margin-left: 380px;">
    		<font size="6px" >千万人在用的知识管理和分享平台</font>
    	</div>
</div>   
    <div data-options="region:'east'" style="width:100px;"></div>   
    <div data-options="region:'west'" style="width:100px;"></div>   
    <div data-options="region:'center'" style="padding:5px">
    	<div id="title">
    		<h1>${article.title}</h1><br>
    		${article.createTime}  &nbsp; &nbsp;
    		<a href="#" style="text-decoration:none"  onclick="userDesc(${article.id})">${article.author} </a>
    		<a href="#" style="text-decoration:none;color: blue;font-size: 18px;margin-left: 25px;" onclick="shoucang(${article.id});">转藏到我的图书馆 </a>
    		<hr>
    	</div>
    	<div id="content">
    		${article.content}  &nbsp; &nbsp;
    		
    		</div>
    		<div id="win">   
    			<form method="post" id="form">
    			<input type="hidden" name="id" value="${article.id}">
    			<div id="visible" style="visibility: hidden;">
    				<div id="titleVisible" style="margin-top: 30px;margin-left: 30px;margin-right: 30px;">
    					<input class="easyui-textbox" name="title" style="width:100%;height: 40px;" value="${article.title}">
    				</div>
    			
		    	<div style="margin-top: 10px;margin-left: 30px;margin-right: 30px;">
					<select id="cc" class="easyui-combobox" name="quanxian" style="width:200px;height: 40px">   
					    <option value="公开">公开</option>   
					    <option value="私密">私密</option>   
					</select>  
				</div>
    			<div style="margin-top: 10px;margin-left: 30px;margin-right: 30px;">
				 	关键字:<br><br>
				 	<input class="easyui-textbox" data-options="required:true" id="commitkey" style="width:300px;height: 30px;" name="key" > <br>
				 	<input id="key" class="easyui-combobox"  data-options="valueField:'keyValue',textField:'keyText',url:'<%=path%>/guancangAction/getKey'" />  
		 
				</div>
				
				
				<div style="margin-top: 10px;margin-left: 30px;margin-right: 30px;">
					选择存放的文件夹:<br><br>
					<ul id="fileTree" data-options="required:true"></ul> 
					<input type="hidden"  name="wenjianjia" id="wenjianjia">
				</div>
    			
    			<div style="margin-top: 10px;margin-left: 30px;margin-right: 30px;">
				 	标签:<br><br>
				 	<input id="label" class="easyui-combobox" name="label" data-options="valueField:'keyValue',textField:'keyText',url:'<%=path%>/guancangAction/getLabel'" />  
				</div>
				
				<div style="margin-top: 10px;margin-left: 90px;margin-top: 30px;">
					<a id="saveBtn" class="easyui-linkbutton"
									data-options="iconCls:'icon-ok'" style="width: 80px; height: 32px;">发表</a>
								<a id="backBtn" class="easyui-linkbutton"
									data-options="iconCls:'icon-back'"
									style="width: 80px; height: 32px;margin-left: 20px">取消</a>
				</div>
    			
    			</div>
    		</form>
			</div>  
			
			
			<div id="pinglunList">
				<h2>网友评论</h2>
				<c:choose>
					<c:when test="${not empty pinglunList}">
						<c:forEach items="${pinglunList}" var="pinglun" varStatus="s">
							评论${s['count']}  :  ${pinglun.content} <br>
						</c:forEach>
					</c:when>
					<c:otherwise>
						暂无评论
					</c:otherwise>
				</c:choose>
			</div>
			
			<div>
				<h2>发表评论</h2>
				<textarea rows="5" cols="150" id="pinglunContent"></textarea>
				<a id="pinglunBtn" class="easyui-linkbutton"
									data-options="iconCls:'icon-ok'" style="width: 80px; height: 32px;margin-left: 900px;">评论</a>
			</div>
    
    </div>  
</body>

</html>